/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-12-15 17:43:11
 * Last Modified: 2017-07-21 18:05:33
 * File Name: controllers/invitation.go
 * Description:
 */
package controllers

import (
	"strings"

	"passport/errorcode"
	"passport/invitecode"
)

type InvitationCheckController struct {
	URLSignController
}

/*
	邀请码合法性检查
*/
func (p *InvitationCheckController) ValidateInviteCode() {
	defer p.Output("ValidateInviteCode")

	p.Resp["code"] = errorcode.EC_GL_SUCCESS
	p.Resp["msg"] = errorcode.Msg(errorcode.EC_GL_SUCCESS)

	inviteCode := strings.ToUpper(p.GetString("invitation", ""))
	if "" == inviteCode { //没有输入邀请码,认为是正确的
		return
	}

	if isSpecialIC := invitecode.GetInviteCodeService().IsSpecialInviteCode(inviteCode); isSpecialIC { //办事处的二维码
		return
	}

	inviteUserid := invitecode.GetInviteCodeService().GetUseridByInviteCode(inviteCode)
	if "" == inviteUserid { //有邀请码的时候,查询到用户ID为空,认为是非法不正确的
		p.Resp["code"] = errorcode.EC_REGISTER_INVITECODE_WRONG
		p.Resp["msg"] = "注册邀请码不正确"
	}
}
